package cn.inbot.shopadmin.module.splash;

import android.os.Bundle;

import com.alibaba.android.arouter.facade.annotation.Route;

import org.jetbrains.annotations.Nullable;

import cn.inbot.shopadmin.R;
import cn.inbot.shopadmin.app.AppCacheData;
import cn.inbot.shopadmin.app.AppGlobalData;
import cn.inbot.shopadmin.app.RouterUrls;
import cn.inbot.shopadmin.bean.LoginResult;
import cn.inbot.lib.framework.PBApplication;
import cn.inbot.lib.framework.annotation.InjectLayout;
import cn.inbot.lib.framework.mvvm.PBActivity;
import cn.inbot.lib.framework.router.PBRouter;
import cn.inbot.lib.util.JsonUtil;
import cn.inbot.lib.util.StringUtil;

/**
 * Created by shisenkun on 2021/5/10.
 */
@Route(path = RouterUrls.DEMO_SPLASH)
@InjectLayout(layoutResId = R.layout.activity_splash)
public class SplashActivity extends PBActivity {

    @Override
    public void initView(@Nullable Bundle savedInstanceState) {
        super.initView(savedInstanceState);

        immersiveStatusBar(R.color.translucent, false);
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        String lastLoginResultJson = AppCacheData.getLastLoginResultJson();
        if(StringUtil.isNotEmpty(lastLoginResultJson)) {
            AppGlobalData.sLoginResult = JsonUtil.jsonToObject(lastLoginResultJson, LoginResult.class);
        }
        PBApplication.mainHandler.postDelayed(this::forwardLoginActivity, 1500);
    }

    private void forwardLoginActivity() {
        PBRouter.INSTANCE.buildWithDefaultAnim(RouterUrls.DEMO_LOGIN).navigation();
        finish();
    }
}
